import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _class;

import React, { PureComponent } from 'react';
import { Table } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import { enableRender, TagRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
import Icons from 'components/Icons';
var modelPrompt = 'ciam.tenantMenu.model.tenantMenu';
var commonPrompt = 'cpaas.common';
var menuIconStyle = {
  width: 14,
  height: 14,
  lineHeight: '14px'
};
var CopyMenuTable = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(CopyMenuTable, _PureComponent);

  var _super = _createSuper(CopyMenuTable);

  function CopyMenuTable() {
    _classCallCheck(this, CopyMenuTable);

    return _super.apply(this, arguments);
  }

  _createClass(CopyMenuTable, [{
    key: "onCell",
    value: function onCell() {
      return {
        style: {
          overflow: 'hidden',
          maxWidth: 220,
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        },
        onClick: function onClick(e) {
          var target = e.target;

          if (target.style.whiteSpace === 'normal') {
            target.style.whiteSpace = 'nowrap';
          } else {
            target.style.whiteSpace = 'normal';
          }
        }
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          loading = _this$props.loading,
          _this$props$menuTypeL = _this$props.menuTypeList,
          menuTypeList = _this$props$menuTypeL === void 0 ? [] : _this$props$menuTypeL,
          dataSource = _this$props.dataSource,
          rowSelection = _this$props.rowSelection;
      var columns = [{
        title: intl.get("".concat(modelPrompt, ".name")).d('目录/菜单'),
        dataIndex: 'name',
        fixed: 'left',
        width: 200
      }, {
        title: intl.get("".concat(modelPrompt, ".parentName")).d('上级目录'),
        width: 120,
        dataIndex: 'parentName'
      }, {
        title: intl.get("".concat(modelPrompt, ".quickIndex")).d('快速索引'),
        width: 120,
        dataIndex: 'quickIndex'
      }, {
        title: intl.get("".concat(modelPrompt, ".icon")).d('图标'),
        width: 60,
        dataIndex: 'icon',
        render: function render(value) {
          return /*#__PURE__*/React.createElement(Icons, {
            type: value,
            size: 14,
            style: menuIconStyle
          });
        }
      }, {
        title: intl.get("".concat(modelPrompt, ".code")).d('编码'),
        dataIndex: 'code',
        onCell: this.onCell.bind(this)
      }, {
        title: intl.get("".concat(modelPrompt, ".menuType")).d('类型'),
        dataIndex: 'type',
        width: 120,
        render: function render(value) {
          var statusList = menuTypeList.map(function (item) {
            return {
              status: item.value,
              color: item.value === 'root' ? 'blue' : item.value === 'dir' ? 'green' : item.value === 'menu' ? 'orange' : 'purple',
              text: item.meaning
            };
          });
          return TagRender(value, statusList);
        }
      }, {
        title: intl.get("".concat(modelPrompt, ".sort")).d('序号'),
        dataIndex: 'sort',
        width: 60
      }, {
        title: intl.get("".concat(modelPrompt, ".description")).d('描述'),
        dataIndex: 'description',
        width: 200,
        onCell: this.onCell.bind(this)
      }, {
        title: intl.get("".concat(commonPrompt, ".status")).d('状态'),
        dataIndex: 'enabledFlag',
        width: 120,
        fixed: 'right',
        render: enableRender
      }].filter(Boolean);
      var tableProps = {
        loading: loading,
        columns: columns,
        dataSource: dataSource,
        pagination: false,
        bordered: true,
        rowKey: 'id',
        childrenColumnName: 'subMenus',
        rowSelection: rowSelection,
        scroll: {
          x: tableScrollWidth(columns)
        }
      };
      return /*#__PURE__*/React.createElement(Table, tableProps);
    }
  }]);

  return CopyMenuTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "onCell", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "onCell"), _class.prototype)), _class));
export { CopyMenuTable as default };